#include "JoystickState.h"
#include "Common.h"

JoystickState::JoystickState()
{
	memset(m_fAxes, 0, sizeof(float) * JOYSTICKSTATE_DEFAULT_AXIS_MAXIMUM);
	memset(m_nButtons, 0, sizeof(unsigned char) * JOYSTICKSTATE_DEFAULT_BUTTON_MAXUMUM);
}

JoystickState::~JoystickState()
{
}

JoystickState JoystickState::GetState(int index)
{
	JoystickState joystickState;

	if(glfwGetJoystickParam(index, GLFW_PRESENT) == GL_TRUE)
	{
		glfwGetJoystickPos(index, joystickState.m_fAxes, JOYSTICKSTATE_DEFAULT_AXIS_MAXIMUM);
		glfwGetJoystickButtons(index, joystickState.m_nButtons, JOYSTICKSTATE_DEFAULT_BUTTON_MAXUMUM);
	}

	return joystickState;
}

const float JoystickState::GetAxis(int axis) const
{
	return m_fAxes[axis];
}

const bool JoystickState::IsButtonDown(int button) const
{
	return m_nButtons[button] == GLFW_PRESS;
}

const bool JoystickState::IsButtonUp(int button) const
{
	return m_nButtons[button] == GLFW_RELEASE;
}